package processingHandling;

import codeanticode.gsvideo.GSCapture;

/**
 * WebCam template PAppletWrapper implementation.
 * Sets up a webcam capture based off the abstract width, height, and frame rate functions.
 * Reads the webcam data into the image each draw call.
 * 
 * @author Dylan James
 *
 */
public abstract class WebCamPAppletWrapper extends PAppletWrapper{
	private int width, height, frameRate;
	private GSCapture cam;
	
	/**
	 * Implemented functionality to be called by the PAppletWrapper class
	 */
	@Override
	public void WrapperSetup() {
		// Initialize this WebCam Wrapper object
		this.Initialize();
		
		// Initialize the applet window based off the given data
		size(width, height);
		background(0);
		fill(255);
		stroke(255);
		frameRate(frameRate);
		
		// Initialize the capture device
		cam = new GSCapture(this, width, height);
		
		// Call the concrete class' setup function
		this.Setup();
	}
	
	/**
	 * Implemented functionality to be called by the PAppletWrapper class
	 */
	@Override
	public void WrapperDraw() {
		// Grab image from the webcam if possible
		if (cam.available() == true){
			cam.read();	

		}
		// Store it
		image(cam, 0, 0);
		// Call the concrete class' draw function
		this.Draw();
	}

	/**
	 * Setup function called at Applet creation.
	 * Implement setup procedure here.
	 */
	public abstract void Setup();
	
	/**
	 * Draw function called at Applet creation.
	 * Implement draw procedure here.
	 */
	public abstract void Draw();
	
	/**
	 * Calls the functions needed to initialize this data.
	 */
	private void Initialize()
	{
		this.width = this.getWidth();
		this.height = this.getHeight();
		this.frameRate = this.getFrameRate();
	}
	
	/**
	 * Abstract function to allow Width setup.
	 * Should return the desired value for the width of the capture window.
	 */
	public abstract int getWidth();
	/**
	 * Abstract function to allow Height setup.
	 * Should return the desired value for the height of the capture window.
	 */
	public abstract int getHeight();
	/**
	 * Abstract function to allow FrameRate setup.
	 * Should return the desired value for the frame rate of the capture.
	 */
	public abstract int getFrameRate();

}
